package com.mz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mz.common.dto.PaginationVo;
import com.mz.common.dto.R;
import com.mz.common.utils.PageDataHandlerUtils;
import com.mz.entity.OmsGoodsCategory;
import com.mz.entity.vo.GoodCategoryVo;
import com.mz.service.OmsGoodsCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

/**
 * (OmsGoodsCategory)表控制层
 *
 * @author makejava
 * @since 2023-12-13 13:38:21
 */
@RestController
@RequestMapping("/omsGoodsCategory")
public class OmsGoodsCategoryController  {
    /**
     * 服务对象
     */
    @Resource
    private OmsGoodsCategoryService omsGoodsCategoryService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/pagination")
    public R getCategoryPagination(PaginationVo paginationVo) throws Exception {

        IPage page = omsGoodsCategoryService.getCategoryPagination( paginationVo );
        return PageDataHandlerUtils.toR(page);
    }


    @GetMapping("/list")
    public R getCategoryAllList() throws Exception {

       List<OmsGoodsCategory> list = omsGoodsCategoryService.getCategoryAllList();
        return R.ok( list );
    }

    /**
     * 新增数据
     * @return 新增结果
     */
    @PostMapping
    public R addGoodsCategory(@RequestBody @Valid GoodCategoryVo goodCategoryVo)  throws Exception {

        omsGoodsCategoryService.addGoodsCategory( goodCategoryVo );
        return R.ok();
    }

    /**
     * 修改数据
     *
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody @Valid GoodCategoryVo goodCategoryVo) throws Exception {

        omsGoodsCategoryService.updateGoodsCategory( goodCategoryVo );
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/remove")
    public R removeGoodsCategory( @RequestBody List<Long> idList)  throws Exception {
        omsGoodsCategoryService.removeGoodsCategory( idList );
        return R.ok();
    }
}

